package com.example.datastructure.sort;

import com.alibaba.fastjson.JSON;

public class Bubbling {
    private int k;

    public static void main(String[] args) {
        int[] array = new int[]{1, 5, 3, 6, 6, 2, 3, 7, 9, 45};
        int count = 0;
        System.out.println(JSON.toJSONString(array));
        for (int i = 0; i < array.length; i++) {// T(n)
            //count++;
            for (int j = 0; j < array.length - i -1; j++) {//45
                if (array[j] > array[j + 1]) {
                    int k = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = k;

                }
                count++;
            }
        }
        System.out.println(count);
        System.out.println(JSON.toJSONString(array));
    }
}
